package com.zsr.chapter04.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author zsr
 * @Description 请求转发
 * @Version 1.0
 */
public class ReqServlet4 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        //获取用户id
        Object userId = request.getAttribute("userId");
        //获取ServletConfig对象
        ServletConfig config = getServletConfig();

        PrintWriter out = response.getWriter();
        out.print("查询编号为"+userId+"的用户信息如下：<br/>");
        out.print("用户名为："+config.getInitParameter("username")+"<br/>");
        out.print("用户年龄为:"+config.getInitParameter("age")+"<br/>");
    }
}
